import React, { useEffect, useState } from 'react';
import { connect } from 'umi';
import { Form, Button, InputNumber, Affix } from 'antd';
import FormCondition from '@/components/FormCondition';
import DrawerCondition from '@/components/DrawerCondition';
import aliOssUpload from '@/utils/aliOssUpload';
import moment from 'moment';
const FormItem = Form.Item;
const ProduceForm = (props) => {
    const { dispatch, visible = {}, onClose, handleCallback, loading } = props;
    const { show = false, detail = {} } = visible;
    const { id } = detail;
    const [form] = Form.useForm();
    const disabledDate = (current) => {
        // 禁用今天之前的日期
        return current && current < moment().endOf('day');
    };

    const disabledDateTime = (current) => {
        if (current && current.isSame(moment(), 'day')) {
            // 如果是今天，禁用过去的时间
            const now = moment();
            return {
                disabledHours: () =>
                    Array.from({ length: now.hour() }, (_, i) => i),
                disabledMinutes: (selectedHour) => {
                    if (selectedHour === now.hour()) {
                        return Array.from({ length: now.minute() }, (_, i) => i);
                    }
                    return [];
                },
                disabledSeconds: (selectedHour, selectedMinute) => {
                    if (selectedHour === now.hour() && selectedMinute === now.minute()) {
                        return Array.from({ length: now.second() }, (_, i) => i);
                    }
                    return [];
                },
            };
        }
        // 非今天日期不禁用时间
        return {};
    };
    const fetchMenuEdit = () => {
        form.validateFields().then(async (values) => {

            dispatch({
                type: 'answering/fakeSaveTeacherTag',
                payload: {
                    ...values,
                    id
                },
                callback: () => {
                    onClose()
                    handleCallback()
                }
            })
        });
    };

    useEffect(() => { }, []);
    const formItems = [
        { label: '标签名称', name: 'tagName', },
    ];

    const modalProps = {
        title: `${detail.id ? '编辑标签' : '新增标签'}`,
        visible: show,
        onClose,
        footer: (
            <Button type="primary" loading={loading} onClick={fetchMenuEdit}>
                确定
            </Button>
        ),
    };

    return (
        <DrawerCondition {...modalProps}>
            <FormCondition form={form} formItems={formItems} initialValues={detail}></FormCondition>
        </DrawerCondition>
    );
};

export default connect(({ loading, }) => ({

    loading: loading.effects['answering/fakeSaveTeacherTag'],
}))(ProduceForm);
